from PyQt5.QtWidgets import QApplication, QMainWindow, QDesktopWidget
import sys

class MainWin(QMainWindow):

    def __init__(self):
        super(MainWin, self).__init__()

        self.setWindowTitle("窗口居中显示")
        self.resize(500, 500)
        self.center()

    def center(self):
        # 获取屏幕坐标系
        screen = QDesktopWidget().screenGeometry()
        # 获取窗口坐标系
        size = self.geometry()
        left = (screen.width() - size.width())/2
        top = (screen.height() - size.height())/2
        self.move(left, top)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = MainWin()
    main.show()
    sys.exit(app.exec_())

